# 项目名称
PROJECT_NAME := monitor

# 默认编译参数
GO := go
GOARCH ?= amd64

# Agent编译目标(默认Linux)
AGENT_GOOS ?= linux
AGENT_GOBUILD := GOOS=$(AGENT_GOOS) GOARCH=$(GOARCH) $(GO) build

# Monitor编译目标(默认当前系统)
MONITOR_GOOS ?= $(shell go env GOOS)
MONITOR_GOBUILD := GOOS=$(MONITOR_GOOS) GOARCH=$(GOARCH) $(GO) build
GOCLEAN := $(GO) clean

# 输出目录
BIN_DIR := bin

# 源代码目录
CMD_DIR := cmd

# 可执行文件
AGENT := $(BIN_DIR)/agent
MONITOR := $(BIN_DIR)/monitor

# 默认目标
.PHONY: all
all: clean build

# 创建输出目录
$(BIN_DIR):
	mkdir -p $(BIN_DIR)

# 编译
.PHONY: build
build: $(BIN_DIR) agent monitor

# 编译agent
.PHONY: agent
agent: $(BIN_DIR)
	$(AGENT_GOBUILD) -o $(AGENT) ./$(CMD_DIR)/agent

# 编译monitor
.PHONY: monitor
monitor: $(BIN_DIR)
	$(MONITOR_GOBUILD) -o $(MONITOR) ./$(CMD_DIR)/monitor

# 清理
.PHONY: clean
clean:
	$(GOCLEAN)
	rm -rf $(BIN_DIR)

# 帮助信息
.PHONY: help
help:
	@echo "使用方法:"
	@echo "  make              - 清理并编译所有可执行文件"
	@echo "  make build        - 编译所有可执行文件"
	@echo "  make clean        - 清理编译产物"
	@echo "  make agent        - 只编译agent"
	@echo "  make monitor      - 只编译monitor"
	@echo "  make help         - 显示帮助信息"